local zongyou = fk.CreateSkill{
  name = "lingling__zongyou",
}

Fk:loadTranslationTable{
  ["lingling__zongyou"] = "纵游",
  [":lingling__zongyou"] = "轮次开始时，你可以选择：摸两张牌，最先进行回合，本轮你下一次受到的伤害+1；摸一张牌，最后进行回合，"..
  "本轮你下一次造成的伤害+1。",

  ["lingling__zongyou-first"] = "摸两张牌，最先进行回合，下次受到伤害+1",
  ["lingling__zongyou-last"] = "摸一张牌，最后进行回合，下次造成伤害+1",
  ["@lingling__zongyou_inflict-round"] = "受到伤害+",
  ["@lingling__zongyou_cause-round"] = "造成伤害+",
}

zongyou:addEffect(fk.RoundStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zongyou.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = {"lingling__zongyou-first", "lingling__zongyou-last", "Cancel"},
      skill_name = zongyou.name,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    local turn_table = data.turn_table or table.simpleClone(room.players)
    table.removeOne(turn_table, player)
    if choice == "lingling__zongyou-first" then
      table.insert(turn_table, 1, player)
      room:setPlayerMark(player, "@lingling__zongyou_inflict-round", 1)
      player:drawCards(2, zongyou.name)
    else
      table.insert(turn_table, player)
      room:setPlayerMark(player, "@lingling__zongyou_cause-round", 1)
      player:drawCards(1, zongyou.name)
    end
    data.turn_table = turn_table
  end,
})

zongyou:addEffect(fk.DamageInflicted, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@lingling__zongyou_inflict-round") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data:changeDamage(player:getMark("@lingling__zongyou_inflict-round"))
    player.room:setPlayerMark(player, "@lingling__zongyou_inflict-round", 0)
  end,
})

zongyou:addEffect(fk.DamageCaused, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@lingling__zongyou_cause-round") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data:changeDamage(player:getMark("@lingling__zongyou_cause-round"))
    player.room:setPlayerMark(player, "@lingling__zongyou_cause-round", 0)
  end,
})

return zongyou
